package com.bbs2.web;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.bbs2.entity.Board;
import com.bbs2.entity.User;
import com.bbs2.service.BoardService;
import com.opensymphony.xwork2.ActionContext;

public class ApplicationAction {
	private List<Board> list = new ArrayList<Board>();
	private User user = new User();
	public String execute(){
		List<Board> list = new BoardService().findAll();
		if(list != null){
			setList(list);
			return "success";
		}else{
			return "error";
		}
	}
	public String login(){
		return "login";
	}
	public String reg(){
		return "reg";
	}
	public String exit(){
		HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
		HttpSession session = request.getSession();
		session.removeAttribute("user");
		session.invalidate();
		return "success";
	}
	//getter setter

	public List<Board> getList() {
		return list;
	}

	public void setList(List<Board> list) {
		this.list = list;
	}
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	
}
